import java.util.ArrayList;
import java.util.List;

/**
 * @program: LeetCode
 * @description: LeetCode : 46. 全排列
 * @author: WXY
 * @create: 2023-01-19 15:13
 * @Version 1.0
 **/
public class Num046_permute {
    public static List<List<Integer>> ans = new ArrayList<>();
    private static List<Integer> path = new ArrayList<>();
    public static List<List<Integer>> permute(int[] nums) {
        boolean[] used = new boolean[nums.length];
        process(nums, used);
        return ans;
    }

    private static void process(int[] arr, boolean[] used) {
        if (path.size() == arr.length) {
            ans.add(new ArrayList<>(path));
            return;
        }
        for (int i = 0; i < arr.length; i++) {
            if (used[i] == true)continue;
            path.add(arr[i]);
            used[i] = true;
            process(arr, used);
            used[i] = false;
            path.remove(path.size() - 1);
        }
    }

    public static void main(String[] args) {
        int[] arr = {1,1,2};
        List<List<Integer>> permute = permute(arr);
        System.out.println(permute);
    }
}
